package com.web.entity.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * @author liuxuhuang
 * @date 2023年03月30日 21:11
 */
@ApiModel()
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString
public class UserRegisterDTO {
    /**
     * 邮箱
     */
    @ApiModelProperty("邮箱")
    @NotBlank(message = "邮箱不能为空")
    @Email(message = "邮箱格式错误")
    private String email;

    /**
     * 密码
     */
    @ApiModelProperty("密码")
    @NotBlank(message = "密码不能为空")
    @Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$", message = "密码要包含字母和数字，要求8-16位")
    private String password;

    /**
     * 确认密码
     */
    @ApiModelProperty("确认密码")
    @NotBlank(message = "确认密码不能为空")
    @Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$", message = "密码强度要包含字母和数字，要求8-16位")
    private String rePassword;

    /**
     * 验证码
     */
    @ApiModelProperty("验证码")
    @NotBlank(message = "验证码不能为空")
    @Size(min = 4, max = 6, message = "验证码为4-6位")
    private String code;

    public String getEmail() {
        return email.replaceAll(" ", "");
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password.replaceAll(" ", "");
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRePassword() {
        return rePassword.replaceAll(" ", "");
    }

    public void setRePassword(String rePassword) {
        this.rePassword = rePassword;
    }

    public String getCode() {
        return code.replaceAll(" ", "");
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof UserRegisterDTO)) return false;

        UserRegisterDTO that = (UserRegisterDTO) o;

        if (getEmail() != null ? !getEmail().equals(that.getEmail()) : that.getEmail() != null) return false;
        if (getPassword() != null ? !getPassword().equals(that.getPassword()) : that.getPassword() != null)
            return false;
        if (getRePassword() != null ? !getRePassword().equals(that.getRePassword()) : that.getRePassword() != null)
            return false;
        return getCode() != null ? getCode().equals(that.getCode()) : that.getCode() == null;
    }

    @Override
    public int hashCode() {
        int result = getEmail() != null ? getEmail().hashCode() : 0;
        result = 31 * result + (getPassword() != null ? getPassword().hashCode() : 0);
        result = 31 * result + (getRePassword() != null ? getRePassword().hashCode() : 0);
        result = 31 * result + (getCode() != null ? getCode().hashCode() : 0);
        return result;
    }
}
